﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using mBlog.Data.Entities;
using System.Data.Objects;
using System.Data.Entity.Infrastructure;
using System.Data.Common;

namespace mBlog.Data
{
    public class mBlogContext : DbContext
    {        
        public DbSet<Post> Posts { get; set; }
        public DbSet<Category> Categories { get; set; }
        public DbSet<Comment> Comments { get; set; }
        public DbSet<Tag> Tags { get; set; }
        public DbSet<SocialShare> Shares { get; set; }
        public DbSet<Link> Links { get; set; }

        public void MarkAsModified(object entity)
        {
            ((IObjectContextAdapter)this).ObjectContext.ObjectStateManager
                .ChangeObjectState(entity, System.Data.EntityState.Modified);

        }

        public void CreateEntityKey(string objectSetName, object entity)
        {
            ((IObjectContextAdapter)this).ObjectContext.CreateEntityKey(objectSetName, entity);
        }

        public DbConnection GetConnection()
        {
            return ((IObjectContextAdapter)this).ObjectContext.Connection;
        }
    }
}
